import Vue from 'vue';
import mask from './main';
let maskComponents = null;

const instances = [];

Vue.directive('mask', {
  bind(el, {
    value,
    oldValue
  }, vnode) {
    maskComponents = mask();
    let zIndex = 990;
    instances.forEach(item => {
      zIndex += 10
    })
    maskComponents.zIndex = zIndex;
    instances.push(maskComponents);
  },
  update(el, {
    value,
    oldValue
  }) {
    if (value === oldValue) return;
    maskComponents.isShow = value;
  },
  unbind(el, {
    value,
    oldValue
  }) {
    instances.pop().isShow = false;
  }
})
